home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-30 | 4.1 KB | 171 lines | [TEXT/ALFA] |
- #===========================================================================
- # Information about a selection or window.
- #===========================================================================
- proc wordCount {} {
- if {[set chars [expr {[selEnd] - [getPos]}]]} {
- set lines [expr {[lindex [posToRowCol [selEnd]] 0] - [lindex [posToRowCol [getPos]] 0]}]
- set text [getSelect]
- } else {
- set chars [maxPos]
- set lines [lindex [posToRowCol $chars] 0]
- set text [getText 0 [maxPos]]
- }
- if {[regsub -all {[!=;.,\(\):\{\"\}]} $text " " ret]} {
- set words [llength $ret]
- } else {
- set words [llength $text]
- }
- alertnote [format "%d chars, %d words, %d lines" $chars $words $lines]
- }
-
- proc matchingLines {} {
- if [catch {prompt "Regular expression:" ""} reg] return
- if {![string length $reg]} return
- set reg ^.*$reg.*$
- set pos [getPos]
- set matches 0
- while {![catch {search -f 1 -r 1 -m 0 -i 1 $reg $pos} mtch]} {
- append lines "\r" [format "%4d: " [lindex [posToRowCol [lindex $mtch 0]] 0]] [eval getText $mtch]
- set pos [lindex $mtch 1]
- incr matches
- }
- new
- insertText [format "%d matching lines\r-----" $matches] $lines "\r"
- }
-
-
- #=============================================================================
- # Random functions.
- #=============================================================================
- proc commentBox {} {
- alertnote "I haven't gotten around to this yet." }
-
- proc uncommentBox {} {
- alertnote "I haven't gotten around to this yet." }
-
- proc transposeWords {} {
- forwardWord
- setMark
- backwardWord
- cut
- deleteChar
- forwardWord
- insertText "\ "
- paste
- }
-
- proc transposeChars {} {
- setMark
- forwardChar
- cut
- backwardChar
- paste
- forwardChar
- }
-
- proc nextFunc {} {
- searchFunc 1
- }
-
- proc prevFunc {} {
- searchFunc 0
- }
-
- proc searchFunc {dir} {
- global funcExpr
- set pos [getPos]
- select $pos
- if ($dir==1) {
- incr pos
- } else {
- set pos [expr $pos-1]
- }
- eval select [search -f $dir -i 1 -r 1 $funcExpr $pos]
- }
- bind Kpad1 prevFunc
- bind Kpad3 nextFunc
-
- #===========================================================================
- # Include file manipulation. - called from Alpha.
- #===========================================================================
- proc openSelection {} {
- global includePath
- global Think
- set path [substituteVars $includePath]
- set fname [getSelect]
- if {[string last ".h" $fname]=="-1"} {
- set fname ${fname}.h
- }
- foreach dir $path {
- if {[file exists $dir$fname]} {
- edit $dir$fname
- return
- }
- }
- beep
- }
- #===========================================================================
- # Add temporary fileset.
- #===========================================================================
- proc addFileset {} {
- global fileSets
- global fileSetNames
- global currFileSet
-
- set name [getline "New fileset name:" ""]
- if {![string length $name]} return
-
- set dir [get_directory]
- if {![string length $dir]} return
-
- set filePat [getline "File pattern:" "*"]
- if {![string length $filePat]} return
-
- set newFSet [glob "$dir:$filePat"]
- lappend fileSets [linsert $newFSet 0 $name]
- lappend fileSetNames $name
- addMenuItem -m fileSets $name
- set currFileSet $name
- }
-
-
- proc getDirPath {} {
- set str [getPathName]
- set ind [string last ":" $str]
- if {$ind != 0} {
- set str [string range $str 0 [expr $ind-1]]
- }
- return $str
- }
-
-
- #===========================================================================
- # Comment routines.
- #===========================================================================
- proc commentPara {} {
- }
-
-
-
- #===========================================================================
- # Sorting the selection.
- # AUTHOR: David C. Black black@mpd.tandem.com
- #===========================================================================
- proc sortLines {} {
- set start [getPos]
- set end [selEnd]
- if {$start == $end} {
- alertnote "You must highlight the section you wish to sort."
- return
- }
- if {[lookAt [expr $end-1]] != "\r"} {
- alertnote "The selection must consist only of complete lines."
- return
- }
- set text [getText $start [expr {$end-1}]]
- set text [join [lsort [split $text "\r"]] "\r"]
- replaceText $start [expr {$end-1}] $text
- select $start $end
- }
-
-